      Subroutine InitHash
      include "param.fi"
      include "common.fi"

      Integer I, J, K, II, IJK
      
      ! Clear the Hash table
      Do I = 1, GRIDNUM
      Do J = 1, GRIDNUM
      Do K = 1, GRIDNUM
        HASSNUMS(I,J,K) = 0
      Enddo
      Enddo
      Enddo

      ! Visit all particles
      Do II = 1, NTOT3T
        I = InBox(X1(II)-XMIN)/GridWidth + 1
        J = InBox(X2(II)-XMIN)/GridWidth + 1
        K = InBox(X3(II)-XMIN)/GridWidth + 1
        HASSNUMS(I,J,K) = HASSNUMS(I,J,K) + 1
        HASSIND(HASSNUMS(I,J,K), I, J, K) = II
        Call HASHINDEX31(I,J,K, IJK)
        HASS(II) = IJK
      Enddo

      End Subroutine
